<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>index</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			
			.home_icon {
				width: 24px;
			}
			
			.mui-bar-tab .mui-tab-item.mui-active {
				color: #004A86;
			}
			
			.mui-bar-tab {
				height: 53px;
				padding-top: 3px;
			}
		</style>
	</head>

	<body>
		
		<!--<header class="mui-bar mui-bar-nav">
			<h1 id="title" class="mui-title">首页</h1>
		</header>-->
		<nav class="mui-bar mui-bar-tab">
			<a id="defaultTab" class="mui-tab-item mui-active" data="pages/index1/shouye1.html">
				<span class="mui-icon ">
					<img src="img/bottom-icon1.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a id="defaultTab1" class="mui-tab-item" data="pages/index1/xiaoxi1.html">
				<span class="mui-icon ">
					<img src="img/bottom-icon2-.png" class="home_icon"/>
				</span>
				<span class="mui-tab-label">消息</span>
			</a>
			<a id="defaultTab2" class="mui-tab-item" data="pages/index1/yingyong1.html">
				<span class="mui-icon ">
					<img src="img/bottom-icon3-.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">应用</span>
			</a>
			<a id="defaultTab3" class="mui-tab-item" data="pages/index1/tongxunlu1.html">
				<span class="mui-icon ">
					<img src="img/bottom-icon4-.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">通讯录</span>
			</a>
			<a id="defaultTab4" class="mui-tab-item" data="pages/index1/my1.html">
				<span class="mui-icon">
					<img src="img/bottom-icon5-.png" class="home_icon"/>
					
				</span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>
		<script src="js/mui.min.js"></script>
		<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
		<script src="./pages/ddms/js/mkeyplus.base.js"></script>
		<script src="./pages/ddms/js/sqlite.js"></script>
		<script type="text/javascript" charset="utf-8">
//		localStorage.clear();
			var name = ""; //用户名
			var cicty = ""; //单位名称
			var qmcount = ""; //待办通知单条数
			var aufcount = ""; //待办工单条数
			var qzpcount = ""; //待办工作票条数
			var first = null; //第一次点击backbutton
			var network;
			console.log("用户名=====" + localStorage.getItem('username'));
			console.log("单位=====" + localStorage.getItem('unit'));
			//mui初始化
			mui.init();
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				network = self.network;
				console.log("network===="+network);
			});
			// 获取 信息缓存
			function getInfo() {
				name = localStorage.getItem("name");
				cicty = localStorage.getItem("cicty");
				qmcount = localStorage.getItem("qmcount");
				aufcount = localStorage.getItem("aufcount");
				qzpcount = localStorage.getItem("qzpcount");
			}
			var subpages = ['pages/index1/shouye1.html', 'pages/index1/xiaoxi1.html', 'pages/index1/yingyong1.html', 'pages/index1/tongxunlu1.html', 'pages/index1/my1.html'];

			var subpage_style = {
				top: '0px',
				bottom: '51px'
			};
			var aniShow = {};
			if(window.plus) {
				plusready();
			} else {
				document.addEventListener('plusready', plusready, false);
			}
			var activeTab;

			function plusready() {
				var self = plus.webview.currentWebview();
				network = self.network;
				for(var i = 0; i < 5; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style,{network:network});
					console.log("窗口ID:" + sub.id);
					if(i != 0) {
						console.log("隐藏的窗口:" + sub.id);
						sub.hide();
					} else {
						temp[subpages[0]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}

				//默认当前激活选项 ，以及id

				activeTab = subpages[0];
				var defaultt = "pages/index1/shouye1.html";
				mui(".mui-bar-tab").on("tap", "a", function() {
					var targetTab = this.getAttribute('data');
					var defaultt = this.getAttribute("id");
					// console.log("当前点击按钮" + targetTab + defaultt);
					if(targetTab == activeTab) {
						return;
					}
					if(mui.os.ios || aniShow[targetTab]) {
						console.log("第二次打开了===" + targetTab);
						//					if(targetTab == "shouye1.html"){
						//						plus.webview.getWebviewById("shouye1.html").evalJS("refreshhome()");
						//					}
						plus.webview.show(targetTab, "fade-in", 0);
					} else {
						//否则，使用fade-in动画，且保存变量
						console.log("else===" + targetTab);
						//					if(targetTab == "shouye1.html"){
						//						plus.webview.getWebviewById("shouye1.html").evalJS("refreshhome()");
						//					}
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						plus.webview.show(targetTab, "fade-in", 0);
					}

					console.log("隐藏的页面：" + activeTab);
					//隐藏当前;
					plus.webview.hide(activeTab);
					//plus.webview.show(targetTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});
			}
			//		mui.back = function(){			
			//			var main = plus.android.runtimeMainActivity();
			// 			main.moveTaskToBack(false);
			//		}
			mui(".mui-bar-tab a").each(function(i, btn) {
				btn.addEventListener('tap', function() {
					for(var j = 0; j < 5; j++) {
						var imgnum = j + 1;
						var imgstr = "img/bottom-icon" + imgnum + "-.png";
						$(".home_icon").eq(j).attr("src", imgstr);
					}
					var thisimgnum = i + 1;
					$(this).find(".home_icon").attr("src", "img/bottom-icon" + thisimgnum + ".png");
					//bottom-icon2-.png
				}, false);
			});
			//监听返回按钮，连续点击两次退出程序
			mui.back = function() {
				//首次按键，提示‘再按一次退出应用’
				if(!first) {
					first = new Date().getTime();
					mui.toast('再按一次退出应用');
					setTimeout(function() {
						first = null;
					}, 800);
				} else {
					if(new Date().getTime() - first < 1000) {
						plus.runtime.quit();
					}
				}
			}
      window.addEventListener("homeOffline", function(e) {
        console.log('离线啊'+e.detail.idList)
        var idList = e.detail.idList;
        var list = e.detail.batchList;
        receive(idList,list);
      });
		</script>
	</body>

</html>